import random

class NumberGame:
    @staticmethod
    def startGame():
        randomIntList = [random.randint(1, 10) for _ in range(4)]
        print(randomIntList)
        result = NumberGame.checkIntList(randomIntList)
        if result is None:
            print("Failed!")
        else:
            print("{:s}=24".format(result))
            
    @staticmethod
    def checkIntList(intList: list) -> str:
        for operator0 in ["", "-"]:
            for operator1 in "+-*/":
                for operator2 in "+-*/":
                    for operator3 in "+-*/":
                        caseString = "{:s}{:d}{:s}{:d}{:s}{:d}{:s}{:d}".format(operator0, intList[0], operator1, intList[1], operator2, intList[2], operator3, intList[3])
                        if NumberGame.checkString(caseString):
                            return caseString
                        caseString = "{:s}({:d}{:s}{:d}){:s}{:d}{:s}{:d}".format(operator0, intList[0], operator1, intList[1], operator2, intList[2], operator3, intList[3])
                        if NumberGame.checkString(caseString):
                            return caseString
                        caseString = "{:s}({:d}{:s}{:d}{:s}{:d}){:s}{:d}".format(operator0, intList[0], operator1, intList[1], operator2, intList[2], operator3, intList[3])
                        if NumberGame.checkString(caseString):
                            return caseString
                        caseString = "{:s}(({:d}{:s}{:d}){:s}{:d}){:s}{:d}".format(operator0, intList[0], operator1, intList[1], operator2, intList[2], operator3, intList[3])
                        if NumberGame.checkString(caseString):
                            return caseString
                        caseString = "{:s}({:d}{:s}({:d}{:s}{:d})){:s}{:d}".format(operator0, intList[0], operator1, intList[1], operator2, intList[2], operator3, intList[3])
                        if NumberGame.checkString(caseString):
                            return caseString
                        caseString = "{:s}{:d}{:s}({:d}{:s}{:d}){:s}{:d}".format(operator0, intList[0], operator1, intList[1], operator2, intList[2], operator3, intList[3])
                        if NumberGame.checkString(caseString):
                            return caseString
                        caseString = "{:s}{:d}{:s}({:d}{:s}{:d}{:s}{:d})".format(operator0, intList[0], operator1, intList[1], operator2, intList[2], operator3, intList[3])
                        if NumberGame.checkString(caseString):
                            return caseString
                        caseString = "{:s}{:d}{:s}(({:d}{:s}{:d}){:s}{:d})".format(operator0, intList[0], operator1, intList[1], operator2, intList[2], operator3, intList[3])
                        if NumberGame.checkString(caseString):
                            return caseString
                        caseString = "{:s}{:d}{:s}({:d}{:s}({:d}{:s}{:d}))".format(operator0, intList[0], operator1, intList[1], operator2, intList[2], operator3, intList[3])
                        if NumberGame.checkString(caseString):
                            return caseString
                        caseString = "{:s}{:d}{:s}{:d}{:s}({:d}{:s}{:d})".format(operator0, intList[0], operator1, intList[1], operator2, intList[2], operator3, intList[3])
                        if NumberGame.checkString(caseString):
                            return caseString
                        caseString = "{:s}({:d}{:s}{:d}){:s}({:d}{:s}{:d})".format(operator0, intList[0], operator1, intList[1], operator2, intList[2], operator3, intList[3])
                        if NumberGame.checkString(caseString):
                            return caseString
        return None

    @staticmethod
    def checkString(caseString: str) -> bool:
        try:
            caseResult = eval(caseString)
            if caseResult == 24:
                return True
            else:
                return False
        except ZeroDivisionError:
            return False


if __name__ == "__main__":
    NumberGame.startGame()